package com.example.aigc_education.job;

import com.example.aigc_education.integration.impl.CozeTokenIntegrationImpI;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

//实现OAuth认证机制，通过定时任务每12小时刷新一次OAuth Token，并将其存储在Redis缓存中，从而避免每30天手动更新PAT。
@Component
@EnableScheduling
public class CozeTokenRefreshJob {
    @Autowired
    private  CozeTokenIntegrationImpI cozeTokenIntegration;

    //    通过定时任务每12小时刷新一次OAuth Token
    @Scheduled(cron = "0 0 13/12 * * ?")
    public void refreshToken()  {
        // 刷新OAuth Token
        try {
            cozeTokenIntegration.reFreshCozeToken();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
